home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / awordp1a / form1.frm next >
Text File  |  1999-10-13  |  11KB  |  346 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
  3. Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.1#0"; "RICHTX32.OCX"
  4. Begin VB.Form Form1 
  5.    Caption         =   "RichTextBox Sample - [Noname]"
  6.    ClientHeight    =   6255
  7.    ClientLeft      =   3360
  8.    ClientTop       =   2295
  9.    ClientWidth     =   9150
  10.    Icon            =   "Form1.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   6255
  13.    ScaleWidth      =   9150
  14.    Begin RichTextLib.RichTextBox RTF2 
  15.       Height          =   1095
  16.       Left            =   9480
  17.       TabIndex        =   1
  18.       Top             =   2040
  19.       Width           =   495
  20.       _ExtentX        =   873
  21.       _ExtentY        =   1931
  22.       _Version        =   327680
  23.       TextRTF         =   $"Form1.frx":0442
  24.    End
  25.    Begin MSComDlg.CommonDialog CommonDialog1 
  26.       Left            =   1320
  27.       Top             =   6240
  28.       _ExtentX        =   847
  29.       _ExtentY        =   847
  30.       _Version        =   327680
  31.       CancelError     =   -1  'True
  32.       Filter          =   "RTF Files|*.RTF|Text Files|*.TXT|All Files|*.*"
  33.    End
  34.    Begin RichTextLib.RichTextBox RTF 
  35.       Height          =   6255
  36.       Left            =   0
  37.       TabIndex        =   0
  38.       Top             =   0
  39.       Width           =   9135
  40.       _ExtentX        =   16113
  41.       _ExtentY        =   11033
  42.       _Version        =   327680
  43.       ScrollBars      =   3
  44.       TextRTF         =   $"Form1.frx":0513
  45.    End
  46.    Begin VB.Menu MenuFile 
  47.       Caption         =   "&File"
  48.       Begin VB.Menu SubMenuNew 
  49.          Caption         =   "&New"
  50.          Shortcut        =   ^N
  51.       End
  52.       Begin VB.Menu SubMenuOpen 
  53.          Caption         =   "&Open..."
  54.          Shortcut        =   ^O
  55.       End
  56.       Begin VB.Menu SubMenuSave 
  57.          Caption         =   "&Save"
  58.          Enabled         =   0   'False
  59.          Shortcut        =   {F2}
  60.       End
  61.       Begin VB.Menu SubMenuSaveAs 
  62.          Caption         =   "&Save As..."
  63.       End
  64.       Begin VB.Menu SubMenuSaveaCopy 
  65.          Caption         =   "&Save a Copy..."
  66.       End
  67.       Begin VB.Menu Separator1 
  68.          Caption         =   "-"
  69.       End
  70.       Begin VB.Menu SubMenuExit 
  71.          Caption         =   "E&xit"
  72.          Shortcut        =   ^Q
  73.       End
  74.    End
  75.    Begin VB.Menu EditMenu 
  76.       Caption         =   "&Edit"
  77.       Begin VB.Menu OpenFindBox 
  78.          Caption         =   "Find..."
  79.          Shortcut        =   {F3}
  80.       End
  81.       Begin VB.Menu Separator3 
  82.          Caption         =   "-"
  83.       End
  84.       Begin VB.Menu EditSW 
  85.          Caption         =   "Select the Word"
  86.          Shortcut        =   ^W
  87.       End
  88.       Begin VB.Menu EditSS 
  89.          Caption         =   "Select the Sentence"
  90.          Shortcut        =   ^S
  91.       End
  92.    End
  93.    Begin VB.Menu MenuFont 
  94.       Caption         =   "F&ont"
  95.       Begin VB.Menu SubMenuRegular 
  96.          Caption         =   "Regular"
  97.       End
  98.       Begin VB.Menu CheckBold 
  99.          Caption         =   "Bold"
  100.          Shortcut        =   ^B
  101.       End
  102.       Begin VB.Menu CheckItalic 
  103.          Caption         =   "Italic"
  104.          Shortcut        =   ^I
  105.       End
  106.       Begin VB.Menu CheckUnderLine 
  107.          Caption         =   "UnderLine"
  108.          Shortcut        =   ^U
  109.       End
  110.       Begin VB.Menu CheckStrikeLine 
  111.          Caption         =   "StrikeLine"
  112.       End
  113.       Begin VB.Menu Separator2 
  114.          Caption         =   "-"
  115.       End
  116.       Begin VB.Menu SubMenuDialog 
  117.          Caption         =   "Dialog Box..."
  118.          Shortcut        =   ^F
  119.       End
  120.    End
  121.    Begin VB.Menu MenuHelp 
  122.       Caption         =   "Help"
  123.       Begin VB.Menu ShowAbout 
  124.          Caption         =   "About..."
  125.          Shortcut        =   {F1}
  126.       End
  127.       Begin VB.Menu ShowShortcut 
  128.          Caption         =   "Show the list of the Shortcut Keys"
  129.       End
  130.    End
  131. End
  132. Attribute VB_Name = "Form1"
  133. Attribute VB_GlobalNameSpace = False
  134. Attribute VB_Creatable = False
  135. Attribute VB_PredeclaredId = True
  136. Attribute VB_Exposed = False
  137. Dim Saved As Boolean
  138. Dim Changed As Boolean
  139. Dim FileName As String
  140. Private Sub CheckBold_Click()
  141. CheckBold.Checked = Not CheckBold.Checked
  142. RTF.SelBold = CheckBold.Checked 'Set RTF.SelBold
  143. End Sub
  144. Private Sub CheckItalic_Click()
  145. CheckItalic.Checked = Not CheckItalic.Checked
  146. RTF.SelItalic = CheckItalic.Checked 'Set RTF.SelItalic
  147. End Sub
  148. Private Sub CheckStrikeLine_Click()
  149. CheckStrikeLine.Checked = Not CheckStrikeLine.Checked
  150. RTF.SelStrikeThru = CheckStrikeLine.Checked  'Set RTF.SelStrikeThru
  151. End Sub
  152. Private Sub CheckUnderLine_Click()
  153. CheckUnderLine.Checked = Not CheckUnderLine.Checked
  154. RTF.SelUnderline = CheckItalic.Checked 'Set RTF.SelUnderline
  155. End Sub
  156. Private Sub EditSS_Click()
  157. SelectSentence
  158. End Sub
  159. Private Sub EditSW_Click()
  160. SelectWord
  161. End Sub
  162. Private Sub Form_Load()
  163. FileName = "Noname"
  164. End Sub
  165. Private Sub Form_Resize()
  166. 'Resize the richtextbox as the form is resized
  167. On Error Resume Next
  168. RTF.Width = Form1.Width - 120
  169. RTF.Height = Form1.Height - 690
  170. End Sub
  171. Private Sub OpenFindBox_Click()
  172. Form2.Show
  173. End Sub
  174. Private Sub RTF_Change()
  175. Changed = True
  176. ChangeCaption
  177. End Sub
  178. Private Sub RTF_KeyUp(KeyCode As Integer, Shift As Integer)
  179. 'If user pushes Ctrl-S, the sentence which the cursor is on will be selected.
  180. 'If user pushes Ctrl-W, the word which the cursor is on will be selected.
  181. 'If user pushes Ctrl-Shift-S, the cursor will move to the end of the sentence.
  182. 'If user pushes Ctrl-Shift-W, the cursor will move to the end of the word.
  183.  
  184. If Shift = vbCtrlMask Then
  185.     Select Case KeyCode
  186.         Case vbKeyS
  187.             SelectSentence
  188.         Case vbKeyW
  189.             SelectWord
  190.     End Select
  191. End If
  192. If Shift = (vbCtrlMask Or vbShiftMask) Then
  193.     Select Case KeyCode
  194.         Case vbKeyS
  195.             RTF.UpTo ".?!", True, False
  196.         Case vbKeyW
  197.             RTF.UpTo ",;:.?! ", True, False
  198.     End Select
  199. End If
  200. End Sub
  201. Private Sub SelectSentence()
  202. RTF.Span ".?!", False, True
  203. SelectionStart = RTF.SelStart
  204. RTF.Span ".?!", True, True
  205. SelectionEnd = RTF.SelStart + RTF.SelLength
  206. RTF.SelStart = SelectionStart
  207. RTF.SelLength = SelectionEnd - SelectionStart
  208. End Sub
  209. Private Sub SelectWord()
  210. RTF.Span " ,;:.?!", False, True
  211. SelectionStart = RTF.SelStart
  212. RTF.Span " ,;:.?!", True, True
  213. SelectionEnd = RTF.SelStart + RTF.SelLength
  214. RTF.SelStart = SelectionStart
  215. RTF.SelLength = SelectionEnd - SelectionStart
  216. End Sub
  217. Private Sub RTF_SelChange()
  218. CheckBold.Checked = IIf(RTF.SelBold = False, False, True)
  219. CheckItalic.Checked = IIf(RTF.SelItalic = False, False, True)
  220. CheckUnderLine.Checked = IIf(RTF.SelUnderline = False, False, True)
  221. CheckStrikeLine.Checked = IIf(RTF.SelStrikeThru = False, False, True)
  222. End Sub
  223.  
  224. Private Sub ShowAbout_Click()
  225. Form1.Enabled = False
  226. Form3.Show
  227. End Sub
  228. Private Sub ShowShortcut_Click()
  229. Form1.Enabled = False
  230. Form4.Show
  231. End Sub
  232. Private Sub SubMenuDialog_Click()
  233. On Error Resume Next
  234. CommonDialog1.Flags = cdlCFBoth
  235. CommonDialog1.ShowFont
  236. RTF.SelFontName = CommonDialog1.FontName
  237. RTF.SelFontSize = CommonDialog1.FontSize
  238. RTF.SelStrikeThru = CommonDialog1.FontStrikethru
  239. RTF.SelUnderline = CommonDialog1.FontUnderline
  240. RTF.SelBold = CommonDialog1.FontBold
  241. RTF.SelItalic = CommonDialog1.FontItalic
  242. End Sub
  243. Private Sub SubMenuNew_Click()
  244. 'Make a new file!
  245. If Changed = True Then
  246. a = MsgBox("Do you want to save [" + FileName + "]?", vbYesNoCancel, "Alert!")
  247. If a = 2 Then Exit Sub
  248. If a = 7 Then GoTo 10
  249. If Saved = True Then SubMenuSave_Click Else SubMenuSaveAs_Click
  250. GoTo 10
  251. Else
  252. 10 RTF.Text = "": Changed = False
  253. ChangeCaption
  254. FileName = "Noname": SubMenuSave.Enabled = False
  255. Saved = False: SubMenuSave.Enabled = False
  256. End If
  257. End Sub
  258. Private Sub SubMenuOpen_Click()
  259. 'Open a saved file!
  260. On Error GoTo 10
  261. If Changed = True Then
  262.     a = MsgBox("Do you want to save [" + FileName + "]?", vbYesNoCancel, "Alert!")
  263.     If a = 2 Then Exit Sub
  264.     If a = 7 Then GoTo 20
  265.     If Saved = True Then SubMenuSave_Click Else SubMenuSaveAs_Click
  266. End If
  267. 20
  268. CommonDialog1.Flag